#include "view.h"

View::View(QWidget *parent) :
    QWidget(parent)
{
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000/_REFRESH_RATE_);
    number = 1;
    last = QTime::currentTime();
}

void View::paintEvent(QPaintEvent* e)
{
    Q_UNUSED(e)

    if((number%60) == 0) {
        QTime now = QTime::currentTime();

        m_fps = QString("%1 fps").arg(60*1000.0/(last.msecsTo(now)));

        last = now;
    }
    QString text = QString::number((++number));
    QPainter painter(this);
    painter.setBackground(QBrush(Qt::red));
    painter.setPen(Qt::NoPen);
    painter.setBrush(QBrush(Qt::black));
    painter.drawRect(QRect(0,0,this->size().width()-1,this->size().height()-1));
    painter.setPen(Qt::white);
    painter.drawText(10,10,text);
    painter.drawText(100,100,m_fps);

}
